package net.tv90.bfmccore.util.HUD;

import lk.vexview.api.VexViewAPI;
import lk.vexview.gui.components.VexImage;
import lk.vexview.hud.VexImageShow;
import net.tv90.bfmccore.util.vector.Vector2i;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.Set;

public class BackGroundImage extends ImageShow{
    public String soundPath;

    public BackGroundImage(String imagePath, int lastTime, String soundPath,String name) {
        super(new Vector2i(-1,-1), new Vector2i(100,100), imagePath, lastTime,name);
        this.soundPath = soundPath;
    }

    @Override
    public void show(Player p) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        VexImage Icon = new VexImage(imagePath, -1, -1, windowWidth, windowHeight);
        VexViewAPI.sendHUD(p, new VexImageShow(name, Icon, lastTime));
        p.playSound(p.getLocation(), soundPath, 100.0F, 1.0F);
    }
    @Override
    public void showToPlayers(Set<Player> list) {
        list.forEach(p -> {
            int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
            int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
            VexImage Icon = new VexImage(imagePath, -1, -1, windowWidth, windowHeight);
            VexViewAPI.sendHUD(p, new VexImageShow(name, Icon, lastTime));
            p.playSound(p.getLocation(), soundPath, 100.0F, 1.0F);
        });
    }
    @Override
    public void showToAllPlayers() {
        Bukkit.getOnlinePlayers().forEach(p -> {
            int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
            int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
            VexImage Icon = new VexImage(imagePath, -1, -1, windowWidth, windowHeight);
            VexViewAPI.sendHUD(p, new VexImageShow(name, Icon, lastTime));
            p.playSound(p.getLocation(), soundPath, 100.0F, 1.0F);
        });
    }
}
